package com.blb.friendsO.service.impl;

import com.blb.friendsO.dao.IFriendsDao;
import com.blb.friendsO.entity.TComment;
import com.blb.friendsO.entity.TFriends;
import com.blb.friendsO.entity.TGood;
import com.blb.friendsO.entity.TFriends;
import com.blb.friendsO.service.IFriendsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import java.sql.SQLException;

@Service
public class FriendsServiceImpl implements IFriendsService {

    @Autowired
    private IFriendsDao friendsDao;

    //获取所有动态
    @Override
    public List<TFriends> getFriends() throws Exception {
        return friendsDao.getFriends();
    }

    //获得所有点赞
    @Override
    public List<TGood> getGood() throws Exception {
        return friendsDao.getGood();
    }

    //获得所有评论
    @Override
    public List<TComment> getComment() throws Exception {
        return friendsDao.getComment();
    }

    @Override
    public void add(TFriends friends) throws SQLException, ClassNotFoundException {
        friendsDao.add(friends);
    }

    @Override
    public void deleteById(int id) throws Exception {
        friendsDao.deleteById(id);
    }

    @Override
    public void addGood(int userId, int friendsID) throws SQLException, ClassNotFoundException {
        int cou = friendsDao.selectGood(userId, friendsID);
        if (cou==0){
            friendsDao.addGood(userId,friendsID);
        }else {
            friendsDao.deleteGood(userId,friendsID);
        }
    }
}
